package com.ufo.store.management.utils;

import android.app.Activity;
import android.content.DialogInterface;
import android.view.Window;

import com.ufo.store.management.R;
import com.ufo.store.management.widget.dialog.DeleteItemDialog;
import com.ufo.store.management.widget.dialog.TipsDialog;
import com.ufo.store.management.widget.dialog.WaitDialog;

public class DialogUtil {
    /**
     * @desc DeleteItemDialog
     * @author taoli
     */
    private static DeleteItemDialog mDeleteItemDialog;

    public static void showDeleteItemDialog(final Activity context, final String tips, final Runnable positiveRunable, final Runnable negativeRunable){
        mDeleteItemDialog = null;
        if ( (mDeleteItemDialog != null && mDeleteItemDialog.getContext() != context) || (mDeleteItemDialog == null )) {
            mDeleteItemDialog = new DeleteItemDialog(context);
            Window window = mDeleteItemDialog.getWindow(); //得到对话框
            window.setWindowAnimations(R.style.dialog_anim_center_style); //设置窗口弹出动画
        }
        mDeleteItemDialog.setTips(tips);
        mDeleteItemDialog.setItemClickListener(new DeleteItemDialog.OnItemClick() {
            @Override
            public void onItemClick(int position) {
                if (position == 0) {
                    //取消
                    positiveRunable.run();
                } else if (position == 1) {
                    //确定
                    negativeRunable.run();
                }
            }
        });
        mDeleteItemDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
            @Override
            public void onDismiss(DialogInterface dialog) {
            }
        });
        mDeleteItemDialog.show();
    }

    public static void hideDeleteItemDialog(){
        if(mDeleteItemDialog!= null && mDeleteItemDialog.isShowing()){
            mDeleteItemDialog.dismiss();
        }
    }



    /**
     * @desc TipsDialog
     * @author taoli
     */
    private static TipsDialog mTipsDialog = null;

    public static void showTipsDialog(final Activity context, final String tips, final Runnable negativeRunable) {
        mTipsDialog = null;
        if ( (mTipsDialog != null && mTipsDialog.getContext() != context) || (mTipsDialog == null)) {
            mTipsDialog = new TipsDialog(context);
            Window window = mTipsDialog.getWindow(); //得到对话框
            window.setWindowAnimations(R.style.dialog_anim_center_style); //设置窗口弹出动画
        }
        mTipsDialog.setTips(tips);
        mTipsDialog.setItemClickListener(new TipsDialog.OnItemClick() {
            @Override
            public void onItemClick(int position) {
                negativeRunable.run();
            }
        });
        mTipsDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
            @Override
            public void onDismiss(DialogInterface dialog) {

            }
        });
        mTipsDialog.show();
    }

    public static void hideTipsDialog(){
        if(mTipsDialog!= null && mTipsDialog.isShowing()){
            mTipsDialog.dismiss();
        }
    }



    /**
     * @desc WaitDialog
     * @author taoli
     */
    private static WaitDialog mWaitDialog;

    public static void showWaitDialog(final Activity context, final String tips) {
        if( (mWaitDialog != null && mWaitDialog.getContext() != context) || (mWaitDialog == null)){
            mWaitDialog = new WaitDialog(context);
            Window window = mWaitDialog.getWindow(); //得到对话框
            window.setWindowAnimations(R.style.dialog_anim_center_style); //设置窗口弹出动画
        }
        mWaitDialog.setMessage(tips);
        mWaitDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
            @Override
            public void onDismiss(DialogInterface dialog) {
            }
        });
        mWaitDialog.show();
    }

    public static void hideWaitDialog(){
        if(mWaitDialog!= null && mWaitDialog.isShowing()){
            mWaitDialog.dismiss();
        }
    }
}
